package com.blackcat.dynamicexcel.dao;

import com.blackcat.dynamicexcel.entity.ExcelTemplate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * Excel模板 Mapper 接口
 * </p>
 *
 * @author blackcat
 * @since 2022-12-23
 */
public interface ExcelTemplateDao extends BaseMapper<ExcelTemplate> {

    /**
     * 查询独立枚举表
     * @author : zhanghui
     * @cteateTime : 2023/11/29 10:38
     * @param codeMeaning 枚举含义
     * @param codeValue 枚举值
     * @param codeTable 枚举表
    */
    @Select("select CONVERT(${codeMeaning}, CHAR) ${codeMeaning},CONVERT(${codeValue}, CHAR) ${codeValue} from ${codeTable}")
    List<Map<String,String>> queryCodeTable(String codeMeaning, String codeValue, String codeTable);

    /**
     * 通用枚举表查询
     * @author : zhanghui
     * @cteateTime : 2023/11/29 10:38
     * @param codeMeaning 枚举含义
     * @param codeValue 枚举值
     * @param codeTable 枚举表
     * @param field 枚举类型字段
     * @param fieldValue 枚举类型值
    */
    @Select("select CONVERT(${codeMeaning}, CHAR) ${codeMeaning},CONVERT(${codeValue}, CHAR) ${codeValue} from ${codeTable} where ${field}=#{fieldValue}")
    List<Map<String,String>> queryCodeTableByCondition(String codeMeaning, String codeValue, String codeTable, String field, String fieldValue);

    /**
     * 执行拼装 SQL
     * @author : zhanghui
     * @cteateTime : 2023/11/29 10:39
     * @param sql 拼装 SQL
    */
    @Select("${sql}")
    void executeDynamicSQL(String sql);

    /**
     * 拼装SQL查询条数
     * @author : zhanghui
     * @cteateTime : 2023/11/29 10:39
     * @param sql 拼装SQL
    */
    @Select("select count(1) from ${sql}")
    String executeDynamicRepeatSQL(String sql);
}
